package com.example.myapplication.tack_08.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.myapplication.R;
import com.example.myapplication.tack_08.data.CommontData;
import com.example.myapplication.utils.OkHttpTool;

import java.util.List;

public class CommentAdapter extends RecyclerView.Adapter<CommentAdapter.My> {
    private List<CommontData.RowsDTO> list;
    private Context context;
    private View view;

    public CommentAdapter(List<CommontData.RowsDTO> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @NonNull
    @Override
    public My onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        view = LayoutInflater.from(context).inflate(R.layout.comment,null);
        return new My(view);
    }

    @Override
    public void onBindViewHolder(@NonNull My holder, int position) {
        Glide.with(context).load(OkHttpTool.URL + list.get(position).getAvatar()).into(holder.imags);
        holder.content.setText(list.get(position).getContent());
        holder.userName.setText(list.get(position).getUserName());
        holder.commentTime.setText(list.get(position).getCommentTime());


    }

    @Override
    public int getItemCount() {
        return list != null?list.size():0;
    }

    public class My extends RecyclerView.ViewHolder{
        private ImageView imags;
        private TextView content;
        private TextView userName;
        private TextView commentTime;
        public My(@NonNull View itemView) {
            super(itemView);
            imags = view.findViewById(R.id.imags);
            content = view.findViewById(R.id.content);
            userName = view.findViewById(R.id.userName);
            commentTime = view.findViewById(R.id.commentTime);

        }
    }
}
